<?php
/**
 * 情報誌アパマンショップのご案内画面モデルクラス<br />
 *
 * @package apamanshop
 * @author K.Ikenaga
 * @copyright　
 */
class Asnnet_Model_MembersLogin extends Asnnet_Model_Base
{

	/**
	 * 企業情報の取得
	 *
	 * @param String $id ID
	 * @return エラーコード
	 */
	public function chkAccount($id = "", $pass = "", $comid = "")
	{
		//DBパラメータ用配列生成
    	$db_params = array();
    	//結果格納用配列生成
		$data = array();

        //=====SQL生成=====
        $sql = '';
        $sql .= 'SELECT M86_COMPANY_CD, M86_COMPANY_NAME, M86_SHATAKU_KOUJYORITSU, M86_GENRU_FLAG, M86_EXPLANATION_DSP_FLG, M86_REQUEST_FLAG, M86_ETC_MAIL ';
		$sql .= ' FROM M86SHATAKU_TEIKEI_COMPANY';
        if ($comid == "") {
			//IDとパスで照合
			$sql .= ' WHERE M86_SYSTEM_ACCOUNT =\''.$id;
			$sql .= '\' AND M86_SYSTEM_PASSWORD = \''.$pass;
		}else{
			//企業CDで照合
			$sql .= ' WHERE M86_COMPANY_CD = \''.$comid;
		}

        $sql .= '\' AND M86_SYSTEM_USE_FLAG = 1';
        $sql .= ' AND M86_START_DATE <= TO_DATE(SYSDATE)';
        $sql .= ' AND M86_DELETE_FLAG = 0';

		//=====データ取得=====
		$result = $this->dbGetList($sql, $db_params);

		return $result;
	}

	/**
	 * 企業情報情報の取得
	 *
	 * @param String $id ID
	 * @return エラーコード
	 */
	public function chkAccountGenru($strComGenruFlg)
	{
		//DBパラメータ用配列生成
    	$db_params = array();
    	$db_params['strComGenruFlg'] = $strComGenruFlg;

  		$strSQL  = "SELECT M86_COMPANY_CD, M86_COMPANY_NAME, M86_SHATAKU_KOUJYORITSU, M86_GENRU_FLAG, M86_ETC_MAIL";
		$strSQL .= " FROM M86SHATAKU_TEIKEI_COMPANY";
		$strSQL .= " WHERE M86_GENRU_FLAG = :strComGenruFlg ";
		$strSQL .= " AND M86_SYSTEM_USE_FLAG = 1";
		$strSQL .= " AND M86_START_DATE <= TO_DATE(SYSDATE) ";
		$strSQL .= " AND M86_DELETE_FLAG = 0";

		//=====データ取得=====
		$result = $this->dbGetList($strSQL, $db_params);

		return $result;
	}

	/**
	 * ログイン回数記録
	 *
	 * @param String $comId 法人ID
	 */
	public function insLoginLog($comId)
	{
		$sql  = "INSERT INTO WEBLOG1_USER.W73SHATAKU_TEIKEI_LOG (";
		$sql .= " W73_COMPANY_CD ";
		$sql .= ",W73_DATE ";
		$sql .= ",W73_ACTION_FLAG ";
		$sql .= ") VALUES (";
		$sql .= " :comId ";
		$sql .= ",sysdate ";
		$sql .= ",1";
		$sql .= ")";
		
		$db_params = array();
		$db_params['comId'] = $comId;
		
		//トランザクションStart
		$this->_db = $this->getDbConnection();
		$this->startTransaction($this->_db);
		try {
			$this->dbExecQuery($sql, $db_params, $this->_db);
			// コミット
			$this->commitTransaction($this->_db);
		}catch (Exception $e) {
			//ロールバック
			$this->rollbackTransaction($this->_db);
			//DBのエラーメッセージをログに書き出す
			__log_debug(__FILE__, __LINE__, __METHOD__, $e->getMessage());
		}
		$this->_db->closeConnection();
	}
}
?>
